<template>
  <div class="overside" :style="`height:${height}px`">
    <div class="content content_pub d-flex jc-content">
      <div
        class="cont_left d-flex jc-between d-flex"
        :class="{'flex-colunm': width>768?true:false  }"
        v-if="width>768?true:false"
      >
        <div class="left_top">登录您的账号来获得最佳体验</div>
        <div class="left_center">You accompany me to grow up, I hold you to old age</div>
        <div class="left_bottom">
          <img
            src="https://dxtoss.oss-cn-hangzhou.aliyuncs.com/img/2020-04/dM2iQphp6IUklL1587198611200418.png"
          />
        </div>
      </div>
      <div class="cont_right d-flex jc-between">
        <div class="right_top">
          <input type="text" placeholder="Your username" v-model="form.username" />
          <input
            type="password"
            placeholder="Password with you"
            style="margin-top: 15px"
            v-model="form.password"
            @keyup.enter.native="login"
          />
        </div>
        <div class="right_center">
          <button @click="login">Login</button>
        </div>
        <div class="right_bottom">The current interface can only be used for login.</div>
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { adminLogin } from "../../api/api.js";
import {Upload} from 'element-ui'
import axios from 'axios'
export default {
  data() {
    return {
      height: 0,
      visible: false,
      width: document.body.clientWidth,
      form: {
        username: "",
        password: ""
      }
    };
  },
  components: {
    Upload
  },
  methods: {
    getClintHeightWith() {
      this.height = window.screen.height;
      // this.width = window.screen.width;
    },
    async login() {
      const { username, password } = this.form;
      if (!username || !password) {
        return this.$message.error("文本不能为空");
      }
      const res = await adminLogin(this.form);
      if (res.data.code === 1) {
        // 注册一个cookie到本地
        const token = res.data.token
        console.log(token);
        localStorage.setItem('token', token)
        this.$message({
          type: "success",
          message: "登录成功"
        });
        this.$store.commit("updateLogin", true);
        this.$router.push("/");
      } else {
        this.$message({
          type: "error",
          message: res.data.message
        });
      }
    },
  },
  watch: {
    width(val) {
      if (!this.timer) {
        console.log(val);
        this.width = val;
        this.timer = true;
        let that = this;
        setTimeout(function() {
          that.timer = false;
        }, 400);
      }
    }
  },
  mounted() {
    this.getClintHeightWith();
    // 监听窗口大小
    window.onresize = () => {
      return (() => {
        this.width = document.body.clientWidth;
      })();
    };
  }
};
</script>

<style scoped>
.overside {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.content {
  border-radius: 10px;
  border: 1px solid #bbb;
  box-shadow: 0 2px 15px 0 rgba(210, 214, 220, 0.5);
  margin: 100px auto;
  z-index: 1000;
  background-color: #fff;
  overflow: hidden;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
.d-flex {
  display: flex;
}
.jc-between {
  justify-content: space-between;
}
.flex-colunm {
  flex-direction: column;
}

@media screen and (min-width: 768px) {
  /* 大屏幕(最小为768px) */
  .content_pub {
    width: 630px;
    height: 400px;
    text-align: left;
  }
  .cont_left {
    width: 50%;
    height: 100%;
    background-color: #f9fafb;
    padding: 36px;
    box-sizing: border-box;
  }
  .left_top {
    font-size: 25px;
  }
  .left_center {
    font-size: 18px;
  }
  .left_bottom img {
    width: 90px;
    margin-bottom: 30px;
  }
  .cont_right {
    width: 50%;
    box-sizing: border-box;
    padding: 30px;
    display: flex;
    flex-direction: column;
  }
  .right_top {
    margin-top: 15px;
  }
  .right_top input {
    border: 1px solid#e4e4e4;
    width: 90%;
    text-align: left;
    height: 48px;
    border-radius: 8px;
    padding-left: 10px;
    outline: none;
  }
  .right_center {
    margin-bottom: 50px;
  }
  .right_center button {
    background: #dc658d;
    border: none;
    padding: 10px 20px;
    border-radius: 19px;
    color: #fff;
    outline: none;
    cursor: pointer;
  }
  .right_center button:active {
    background: #ff7ba6;
  }
  .right_bottom {
    margin-bottom: 30px;
  }
}
@media screen and (max-width: 768px) {
  /* 小屏幕(最小为768px) */
  .content_pub {
    width: 350px;
    height: 400px;
  }
  .content {
    margin-top: 80% !important;
  }
  .cont_left {
    width: 100%;
    height: 50%;
    background-color: #f9fafb;
    padding: 36px;
    box-sizing: border-box;
  }
  .left_top {
    font-size: 25px;
  }
  .left_center {
    font-size: 18px;
  }
  .left_bottom img {
    width: 90px;
    margin-bottom: 30px;
  }
  .cont_right {
    width: 90%;
    box-sizing: border-box;
    padding: 30px;
    display: flex;
    flex-direction: column;
  }
  .right_top {
    margin-top: 15px;
  }
  .right_top input {
    border: 1px solid#e4e4e4;
    width: 90%;
    text-align: left;
    height: 42px;
    border-radius: 8px;
    padding-left: 10px;
    outline: none;
  }
  .right_center {
    margin-bottom: 80px;
    margin-right: 40px;
  }
  .right_center button {
    background: #dc658d;
    border: none;
    width: 200px;
    height: 40px;
    padding: 10px 20px;
    border-radius: 19px;
    color: #fff;
    outline: none;
  }
  .right_center button:active {
    background: #ff7ba6;
  }
  .right_bottom {
    margin-bottom: 30px;
  }
}
</style>